package com.zzptc.easyshop.servlet;

import com.zzptc.easyshop.dao.IDAO;
import com.zzptc.easyshop.dao.UserDao;
import com.zzptc.easyshop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

@WebServlet(name = "AjaxQueryUserServlet")
public class AjaxQueryUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        String id=request.getParameter("userid");
        IDAO dao=new UserDao();
        boolean i=false;
        HttpSession session=request.getSession();
        PrintWriter pw=response.getWriter();
        try {
            i=((UserDao) dao).isUserID(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (i){
            pw.print("用户名已经存在");
        }else {
            pw.print("用户名可以使用");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
